# coding=utf-8
import random
import numpy as np


def bubbleSort(arr):
    '''冒泡排序'''
    n = len (arr)

    # 遍历所有数组元素
    for i in range (n):

        # Last i elements are already in place
        for j in range (0, n - i - 1):

            if arr[j] > arr[j + 1]:
                arr[j], arr[j + 1] = arr[j + 1], arr[j]

    print ("排序后的数组:")
    print (arr)



def fibonacci():
    '''斐波那契数列实现'''
    # 获取用户输入数据
    nterms = int (input ("你需要几项？"))

    # 第一和第二项
    n1 = 0
    n2 = 1
    count = 2

    # 判断输入的值是否合法
    if nterms <= 0:
        print ("请输入一个正整数。")
    elif nterms == 1:
        print ("斐波那契数列：")
        print (n1)
    else:
        print ("斐波那契数列：")
        print (n1, ",", n2, end=" , ")
        while count < nterms:
            nth = n1 + n2
            print (nth, end=" , ")
            # 更新值
            n1 = n2
            n2 = nth
            count += 1


def isPalindrome(x):
    '''回文数判断，回文数是指正序（从左向右）和倒序（从右向左）读都是一样的整数'''
    if x < 0:  # 当数字是负数的时候必然不是回文数
        return False
    result = 0
    temp = x
    while temp != 0:
        result = result * 10 + temp % 10
        temp = temp // 10
        print (result, temp)
    return x == result


def guess_num():
    '''猜数字小游戏'''

    while True:
        num = input ("请在40-50之间猜一个数字：")
        i = random.randint (40, 50)
        print (i)
        if str (i) == num:
            print ("恭喜你猜中啦")
            break


def get_stepResult(n):
    '''经典爬楼梯方式数计算问题'''
    result = []

    def detailSteps(n, temp=''):
        if sum ([int (x) for x in temp]) == n:
            result.append (temp)
            return
        if sum ([int (x) for x in temp]) > n:
            return
        for i in range (1, 4):  # 限定每次爬楼梯的步数
            detailSteps (n, temp + str (i))

    detailSteps (n)
    return result


def reverseStr(s, k):
    '''反转字符串'''
    if len (s) >= k and len (s) <= 2 * k:  # 当长度小于2k的时候结束递归,返回处理后的字符串
        return s[:k][::-1] + s[k:2 * k]
    elif len (s) < k:  # 当长度小于k的时候，直接反转字符串并返回
        return s[::-1]
    else:
        return s[:k][::-1] + s[k:2 * k] + reverseStr (s[2 * k:], k)  # 当长度大于2k的时候递归处理2k长度的字符串并且递归处理接下来的字符串

def compare_list(list1,list2):
    '''判断数组是否一致'''
    a = np.array (list1)
    b = np.array (list2)
    if ((a == b).all ()):
        print("两个数组一致！")
    else:
        print("两个数据不相同奥！")

if __name__ == '__main__':
    # print (get_stepResult (4))
    # print (len (get_stepResult (4)))
    # arr = [64, 34, 25, 12, 22, 11, 90]
    # bubbleSort (arr)
    compare_list("[1,2,2,5]","[1,2,2,5]")
